﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;
using TimeTracker.Model;

namespace TimeTracker.Data
{
    public class TimeTrackerDbContext : DbContext
    {
        public TimeTrackerDbContext() : base (nameOrConnectionString: "TimeTracker") {
           // Database.SetInitializer<TimeTrackerDbContext>(new TimeTrackerDbInitializer());
        }

        public DbSet<Activity> Activities { get; set; }
        public DbSet<Task> Tasks { get; set; }
        public DbSet<TimeEntry> TimeEntries { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            //modelBuilder.Configurations.Add(new SessionConfiguration())
        }
    }

    public class TimeTrackerDbInitializer : DropCreateDatabaseIfModelChanges<TimeTrackerDbContext>
    {
        protected override void Seed(TimeTrackerDbContext context)
        {
            #region Activities
            context.Activities.Add(new Activity { Id = 1, Name = "Research",    Description = "To receive PhD degree do a research work" });
            context.Activities.Add(new Activity { Id = 2, Name = "Work",        Description = "To make a lot of money" });
            context.Activities.Add(new Activity { Id = 3, Name = "Projects",    Description = "To be a great expert in different things" });
            context.Activities.Add(new Activity { Id = 4, Name = "Blogs",       Description = "To be a famous" });
            context.Activities.Add(new Activity { Id = 5, Name = "Business",    Description = "To have a stable business" });
            context.Activities.Add(new Activity { Id = 6, Name = "Speaking",    Description = "To be famous again" });
            context.Activities.Add(new Activity { Id = 7, Name = "Rest",        Description = "To not go mad" });
            #endregion
            /*
            #region Tasks
            context.Tasks.Add(new Task { Id = 1, Name = "task 1", Importance = 3, Urgency = 1});
            context.Tasks.Add(new Task { Id = 2, Name = "task 2", Importance = 2, Urgency = 2 });
            context.Tasks.Add(new Task { Id = 3, Name = "task 3", Importance = 1, Urgency = 4 });
            context.Tasks.Add(new Task { Id = 4, Name = "task 4", Importance = 5, Urgency = 5 });
            #endregion
            */
        }
    }
}
